home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / MSWSRC35.ZIP / GRAPHWIN.CPP < prev    next >
C/C++ Source or Header  |  1993-10-12  |  48KB  |  1,828 lines

  1. #include "allwind.h"
  2.  
  3. extern HBITMAP DIBToBitmap (HANDLE hDIB, HPALETTE hPal);
  4. extern HANDLE BitmapToDIB (HBITMAP hBitmap, HPALETTE hPal);
  5.  
  6. char *tempfont;
  7. int found;
  8. int printflag;
  9. long bitmode = SRCCOPY;
  10.  
  11. NODE *lbitsave(NODE *arg)
  12.    {
  13.    char textbuf[MAX_BUFFER_SIZE];
  14.    
  15.    /* same as BITMAP-SAVE but gets file name from logo command */
  16.    
  17.    cnv_strnode_string(textbuf,arg);
  18.    
  19.    ((TMyWindow *)MainWindowx)->DumpBitmapFile(textbuf);
  20.    
  21.    return(UNBOUND);
  22.    }
  23.  
  24. NODE *lbitload(NODE *arg)
  25.    {
  26.    char textbuf[MAX_BUFFER_SIZE];
  27.    
  28.    /* same as BITMAP-LOAD except callable from logo command */
  29.    
  30.    cnv_strnode_string(textbuf,arg);
  31.    
  32.    ((TMyWindow *)MainWindowx)->LoadBitmapFile(textbuf);
  33.    
  34.    return(UNBOUND);
  35.    }
  36.  
  37. // function that returns the RGB vector of the pixel the turtle is on top of
  38.  
  39. NODE *lpixel()
  40.    {
  41.    HDC MemDC;
  42.    HDC ScreenDC;
  43.    COLORREF the_color;
  44.    
  45.    ScreenDC = GetDC(MainHWindow);
  46.    
  47.    // memory
  48.    
  49.    MemDC = CreateCompatibleDC(ScreenDC);
  50.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  51.    
  52.    if (EnablePalette)
  53.       {
  54.       OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  55.       RealizePalette(MemDC);
  56.       }
  57.    
  58.    the_color = GetPixel(MemDC,turtle_x+xoffset,-turtle_y+yoffset);
  59.    
  60.    if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  61.    
  62.    DeleteDC(MemDC);
  63.    ReleaseDC(MainHWindow, ScreenDC);
  64.    
  65.    return(
  66.    cons(make_intnode((FIXNUM)GetRValue(the_color)),
  67.    cons(make_intnode((FIXNUM)GetGValue(the_color)),
  68.    cons(make_intnode((FIXNUM)GetBValue(the_color)),
  69.    NIL
  70.    ))));
  71.    }
  72.  
  73. void logofill()
  74.    {
  75.    HDC ScreenDC;
  76.    HDC MemDC;
  77.    HBRUSH JunkBrush;
  78.    
  79.    ScreenDC = GetDC(MainHWindow);
  80.    
  81.    JunkBrush = CreateBrushIndirect(&FloodBrush);
  82.    
  83.    // memory
  84.    
  85.    MemDC = CreateCompatibleDC(ScreenDC);
  86.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  87.    
  88.    if (EnablePalette)
  89.       {
  90.       OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  91.       RealizePalette(MemDC);
  92.       }
  93.    
  94.    SetTextColor(MemDC,pcolor);
  95.    
  96.    OldBrush = (HBRUSH)SelectObject(MemDC, JunkBrush);
  97.    
  98.    FloodFill(MemDC,turtle_x+xoffset,-turtle_y+yoffset,pcolor);
  99.    
  100.    if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  101.    SelectObject(MemDC, OldBrush);
  102.    SelectObject(MemDC, OldBitmap);
  103.    
  104.    DeleteDC(MemDC);
  105.    
  106.    //screen
  107.    
  108.    if (zoom_flag)
  109.       {
  110.       SetMapMode(ScreenDC, MM_ANISOTROPIC);
  111.       SetWindowOrg(ScreenDC, 0, 0);
  112.       SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  113.       SetViewportOrg(ScreenDC, 0, 0);
  114.       SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  115.       }
  116.    
  117.    //   SetCapture(MainHWindow);
  118.    
  119.    SetTextColor(ScreenDC,pcolor);
  120.    
  121.    if (EnablePalette)
  122.       {
  123.       OldPalette = SelectPalette(ScreenDC, ThePalette, FALSE);
  124.       RealizePalette(ScreenDC);
  125.       }
  126.    
  127.    OldBrush = (HBRUSH)SelectObject(ScreenDC, JunkBrush);
  128.    
  129.    FloodFill(ScreenDC,
  130.    +turtle_x-((TMyWindow *)MainWindowx)->Scroller->XPos/the_zoom+xoffset,
  131.    -turtle_y-((TMyWindow *)MainWindowx)->Scroller->YPos/the_zoom+yoffset,
  132.    pcolor);
  133.    
  134.    SelectObject(ScreenDC, OldBrush);
  135.    if (EnablePalette) SelectPalette(ScreenDC, OldPalette, FALSE);
  136.    
  137.    DeleteObject(JunkBrush);
  138.    //   ReleaseCapture();
  139.    ReleaseDC(MainHWindow, ScreenDC);
  140.    
  141.    }
  142.  
  143. NODE *lpencolor()
  144.    {
  145.    return(
  146.    cons(make_intnode((FIXNUM)dpenr),
  147.    cons(make_intnode((FIXNUM)dpeng),
  148.    cons(make_intnode((FIXNUM)dpenb),
  149.    NIL
  150.    ))));
  151.    }
  152.  
  153. // funtion to set the pen color while updating palette if need be
  154.  
  155. void thepencolor(int r, int g, int b) /*routine*/
  156.    {
  157.    
  158.    dpenr = r;
  159.    dpeng = g;
  160.    dpenb = b;
  161.    
  162.    if (EnablePalette)
  163.       {
  164.       pcolor = LoadColor((int)dpenr,(int)dpeng,(int)dpenb);
  165.       }
  166.    else
  167.       {
  168.       pcolor = RGB(dpenr,dpeng,dpenb);
  169.       }   
  170.    
  171.    NormalPen.lopnStyle   = PS_INSIDEFRAME;
  172.    NormalPen.lopnWidth.x = width;
  173.    NormalPen.lopnColor   = pcolor;
  174.    }
  175.  
  176. // function to return flood color as a RGB list
  177.  
  178. NODE *lfloodcolor()
  179.    {
  180.    return(
  181.    cons(make_intnode((FIXNUM)dfldr),
  182.    cons(make_intnode((FIXNUM)dfldg),
  183.    cons(make_intnode((FIXNUM)dfldb),
  184.    NIL
  185.    ))));
  186.    }
  187.  
  188. // funtion to set the flood color while updating palette if need be
  189.  
  190. void thefloodcolor(int r, int g, int b) /*routine*/
  191.    {
  192.    
  193.    dfldr = r;
  194.    dfldg = g;
  195.    dfldb = b;
  196.    
  197.    if (EnablePalette)
  198.       {
  199.       fcolor = LoadColor((int)dfldr,(int)dfldg,(int)dfldb);
  200.       }
  201.    else
  202.       {
  203.       fcolor = RGB(dfldr,dfldg,dfldb);
  204.       }
  205.    
  206.    FloodBrush.lbStyle = BS_SOLID;
  207.    FloodBrush.lbColor = fcolor;
  208.    FloodBrush.lbHatch = HS_VERTICAL;
  209.    }
  210.  
  211. // function to return screen color as a RGB list
  212.  
  213. NODE *lscreencolor()
  214.    {
  215.    return(
  216.    cons(make_intnode((FIXNUM)dscnr),
  217.    cons(make_intnode((FIXNUM)dscng),
  218.    cons(make_intnode((FIXNUM)dscnb),
  219.    NIL
  220.    ))));
  221.    }
  222.  
  223. // funtion to set the screen color while updating palette if need be
  224.  
  225. void thescreencolor(int r, int g, int b) /*routine*/
  226.    {
  227.    HDC ScreenDC;
  228.    HDC MemDC;
  229.    
  230.    HBRUSH TempBrush;
  231.    
  232.    dscnr = r;
  233.    dscng = g;
  234.    dscnb = b;
  235.    
  236.    if (EnablePalette)
  237.       {
  238.       scolor = LoadColor((int)dscnr,(int)dscng,(int)dscnb);
  239.       }
  240.    else
  241.       {
  242.       scolor = RGB(dscnr,dscng,dscnb);
  243.       }
  244.    
  245.    ScreenBrush.lbStyle = BS_SOLID;
  246.    ScreenBrush.lbColor = scolor;
  247.    ScreenBrush.lbHatch = HS_VERTICAL;
  248.    
  249.    // When the screen changes we change the erase pen which basically
  250.    // writes the screen color
  251.    
  252.    ErasePen.lopnStyle   = PS_INSIDEFRAME;
  253.    ErasePen.lopnWidth.x = width;
  254.    ErasePen.lopnColor   = scolor;
  255.    
  256.    TempBrush = CreateBrushIndirect(&ScreenBrush);
  257.    
  258.    ScreenDC = GetDC(MainHWindow);
  259.    
  260.    // memory
  261.    
  262.    MemDC = CreateCompatibleDC(ScreenDC);
  263.    OldBitmap = (HBITMAP)SelectObject(MemDC, MemoryBitMap);
  264.    
  265.    if (EnablePalette)
  266.       {
  267.       OldPalette = SelectPalette(MemDC, ThePalette, FALSE);
  268.       RealizePalette(MemDC);
  269.       }
  270.    
  271.    FillRect(MemDC, &FullRect, TempBrush);
  272.    
  273.    if (EnablePalette) SelectPalette(MemDC, OldPalette, FALSE);
  274.    
  275.    SelectObject(MemDC, OldBitmap);
  276.    DeleteDC(MemDC);
  277.    
  278.    // screen
  279.    
  280.    if (zoom_flag)
  281.       {
  282.       SetMapMode(ScreenDC, MM_ANISOTROPIC);
  283.       SetWindowOrg(ScreenDC, 0, 0);
  284.       SetWindowExt(ScreenDC, BitMapWidth, BitMapHeight);
  285.       SetViewportOrg(ScreenDC, 0, 0);
  286.       SetViewportExt(ScreenDC, (int)(BitMapWidth*the_zoom), (int)(BitMapHeight*the_zoom));
  287.       }
  288.    
  289.    if (EnablePalette)
  290.       {
  291.       OldPalette = SelectPalette(ScreenDC, ThePalette, FALSE);
  292.       RealizePalette(ScreenDC);
  293.       }
  294.    
  295.    FillRect(ScreenDC, &TempRect, TempBrush);
  296.    
  297.    SetBkColor(ScreenDC, scolor);
  298.    SetBkMode(ScreenDC, TRANSPARENT);
  299.    
  300.    if (EnablePalette) SelectPalette(ScreenDC, OldPalette, FALSE);
  301.    
  302.    ReleaseDC(MainHWindow, ScreenDC);
  303.    DeleteObject(TempBrush);
  304.    
  305.    InvalidateRect(MainHWindow, NULL, TRUE);
  306.    }
  307.  
  308. int get_ibm_pen_width()
  309.    {
  310.    int w;
  311.    
  312.    w = width;
  313.    
  314.    return (w);
  315.    }
  316.  
  317. //int get_ibm_pen_height()
  318.    //{
  319.    //  int w;
  320.    //
  321.    //  w = width;
  322.    //
  323.    //  return (w);
  324.    //}
  325.  
  326. void set_ibm_pen_width(int w)
  327.    {
  328.    width = w;
  329.    
  330.    // we erase with the same pen width as we write
  331.    
  332.    NormalPen.lopnStyle   = PS_INSIDEFRAME;
  333.    NormalPen.lopnWidth.x = width;
  334.    NormalPen.lopnColor   = pcolor;
  335.    
  336.    ErasePen.lopnStyle   = PS_INSIDEFRAME;
  337.    ErasePen.lopnWidth.x = width;
  338.    ErasePen.lopnColor   = scolor;
  339.    }
  340.  
  341. NODE *lclearpalette(void) /*routine*/
  342.    {
  343.    
  344.    // kill the palette and recreate it with just black and white
  345.    
  346.    if (NOT_THROWING)
  347.       {
  348.       if (EnablePalette)
  349.          {
  350.          DeleteObject(ThePalette);
  351.          
  352.          MyLogPalette->palNumEntries = 2;
  353.          
  354.          if (status_flag) update_status_paletteuse();
  355.          
  356.          ThePalette = CreatePalette(MyLogPalette);
  357.          
  358.          InvalidateRect(MainHWindow, NULL, TRUE);
  359.          }
  360.       }
  361.    
  362.    retur